package com.wanxi.util;


import com.wanxi.domain.dto.OrderStatus;
import org.springframework.core.convert.converter.Converter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author LiuYuRong
 * @Date 2022/1/8 13:58
 * @Version 1.0
 * @Description
 */
public  class OrderStatusConverter implements Converter<Integer, OrderStatus> {
    private Map<Integer,OrderStatus> enumMap= new HashMap<>();

    public OrderStatusConverter() {
        for (OrderStatus orderStatus:OrderStatus.values()){
            enumMap.put(orderStatus.getStatus(),orderStatus);
        }
    }

    @Override
    public OrderStatus convert(Integer source) {
        OrderStatus orderStatus=enumMap.get(source);
        if (orderStatus==null){
            throw new IllegalArgumentException("没有这个枚举类型");
        }
        return orderStatus;
    }
}
